home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2003 December / The Sunday Times - The Month 2003-12.iso / pc / engine / shell / shell.swf / scripts / DefineSprite_105 / frame_1 / DoAction.as
Encoding:
Text File  |  2003-11-10  |  4.8 KB  |  226 lines

  1. function prepare(str)
  2. {
  3.    clearUp();
  4.    if(str == "")
  5.    {
  6.       return undefined;
  7.    }
  8.    numCurrent = -1;
  9.    strPlaylistID = str;
  10.    enabled = true;
  11.    var xmlAdverts = new XML();
  12.    xmlAdverts.ignoreWhite = true;
  13.    xmlAdverts.onLoad = function()
  14.    {
  15.       xmlPlaylist = xmlAdverts.byPath("adverts/@" + strPlaylistID);
  16.       delete xmlAdverts;
  17.       next();
  18.    };
  19.    xmlAdverts.load(ADVERTS_DATA);
  20. }
  21. function start()
  22. {
  23.    next();
  24. }
  25. function clearUp()
  26. {
  27.    mc_file.unloadMovie();
  28.    delete mc_file.onEnterFrame;
  29.    clearInterval(numWaitID);
  30.    enabled = false;
  31.    delete strPlaylistID;
  32.    delete xmlPlaylist;
  33. }
  34. function onClicked()
  35. {
  36.    if(Tardis.Childlock.active == true)
  37.    {
  38.       return undefined;
  39.    }
  40.    var strWebURL = ndCurrent.attributes.web;
  41.    if(strWebURL != null)
  42.    {
  43.       Tardis.webPageOpen(strWebURL);
  44.    }
  45.    else
  46.    {
  47.       if(Tardis.PLAY_MODE == "browser")
  48.       {
  49.          return undefined;
  50.       }
  51.       var file = ndCurrent.attributes.overlay;
  52.       if(file == null || file == "")
  53.       {
  54.          error("adverts : onClicked : no file specified");
  55.       }
  56.       else
  57.       {
  58.          interrupt();
  59.          Tardis.transition.clrTint = parseInt("0x" + ndCurrent.attributes.overlaycolor);
  60.          Tardis.overlay.showAdvert(file);
  61.          var strLog = xmlPlaylist.attributes.index + "." + numCurrent;
  62.          Tardis.UsageData.addAdvertEntry(strLog);
  63.       }
  64.    }
  65. }
  66. function onAnimationfinished()
  67. {
  68.    fadeDown();
  69. }
  70. function interrupt()
  71. {
  72.    if(enabled == false)
  73.    {
  74.       error("adverts : interrupt : adverts not enabled");
  75.    }
  76.    var strWaitMode = ndCurrent.attributes.wait;
  77.    switch(strWaitMode)
  78.    {
  79.       case "swfend":
  80.          mc_file.onEnterFrame = null;
  81.          mc_file.stop();
  82.          break;
  83.       case "static":
  84.       case "script":
  85.          break;
  86.       default:
  87.          if(parseInt(strWaitMode) == strWaitMode)
  88.          {
  89.             clearInterval(numWaitID);
  90.             break;
  91.          }
  92.    }
  93. }
  94. function resume()
  95. {
  96.    if(enabled == false)
  97.    {
  98.       error("adverts : resume : adverts not enabled");
  99.    }
  100.    startWait();
  101. }
  102. function fadeDown()
  103. {
  104.    clearInterval(numWaitID);
  105.    if(enabled == false)
  106.    {
  107.       return undefined;
  108.    }
  109.    mc_file.onEnterFrame = function()
  110.    {
  111.       with(this)
  112.       {
  113.          _alpha -= 10;
  114.          if(_alpha <= 0)
  115.          {
  116.             onEnterFrame = null;
  117.             _parent.next();
  118.          }
  119.       }
  120.    };
  121. }
  122. function fadeUp()
  123. {
  124.    with(this)
  125.    {
  126.       _alpha += 10;
  127.       if(_alpha >= 100)
  128.       {
  129.          _alpha = 100;
  130.          play();
  131.          onEnterFrame = null;
  132.          _parent.enableButton();
  133.          _parent.startWait();
  134.       }
  135.    }
  136. }
  137. function next()
  138. {
  139.    numCurrent++;
  140.    if(numCurrent == xmlPlaylist.childNodes.length)
  141.    {
  142.       numCurrent = 0;
  143.    }
  144.    ndCurrent = xmlPlaylist.byIndex(numCurrent);
  145.    mc_file.removeMovieClip();
  146.    this.createEmptyMovieClip("mc_file",++depth);
  147.    mc_file._alpha = 0;
  148.    var f = function()
  149.    {
  150.       this.onLoad = null;
  151.       this.onEnterFrame = this._parent.fadeUp;
  152.    };
  153.    mc_file = _parent.adverts.mc_file;
  154.    mc_file.onLoad = f;
  155.    mc_file.loadMovie(ADVERT_PATH + ndCurrent.attributes.file);
  156.    trace("******  load advert: " + (ADVERT_PATH + ndCurrent.attributes.file));
  157. }
  158. function enableButton()
  159. {
  160.    ┬º┬ºpush(mc_file);
  161.    ┬º┬ºpush("onRelease");
  162.    if(ndCurrent.attributes.usebutton == "false")
  163.    {
  164.       ┬º┬ºpush(null);
  165.    }
  166.    ┬º┬ºpop()[┬º┬ºpop()] = ┬º┬ºpop();
  167.    mc_file.onRollOver = function()
  168.    {
  169.       onRollover();
  170.    };
  171. }
  172. function startWait()
  173. {
  174.    var strWaitMode = ndCurrent.attributes.wait;
  175.    switch(strWaitMode)
  176.    {
  177.       case "swfend":
  178.          mc_file.play();
  179.          mc_file.onEnterFrame = function()
  180.          {
  181.             with(this)
  182.             {
  183.                if(_currentframe == _totalframes)
  184.                {
  185.                   stop();
  186.                   onEnterFrame = null;
  187.                   _parent.fadeDown();
  188.                }
  189.             }
  190.          };
  191.          break;
  192.       case "static":
  193.       case "script":
  194.          break;
  195.       default:
  196.          if(parseInt(strWaitMode) == strWaitMode)
  197.          {
  198.             numWaitID = setInterval(this,"fadeDown",strWaitMode * 1000);
  199.             break;
  200.          }
  201.          error("startWait : wait mode not recognised");
  202.          break;
  203.    }
  204. }
  205. stop();
  206. ADVERT_PATH = Tardis.ASSETS_FOLDER + "adverts/";
  207. ADVERTS_DATA = Tardis.ASSETS_FOLDER + "xml/adverts.xml";
  208. var numWaitID;
  209. var numCurrent;
  210. var clpMask = this.createEmptyMovieClip("mc_mask",++depth);
  211. var w = 187;
  212. var h = 105;
  213. clpMask.moveTo(0,0);
  214. clpMask.beginFill(16711680);
  215. clpMask.lineTo(w,0);
  216. clpMask.lineTo(w,h);
  217. clpMask.lineTo(0,h);
  218. clpMask.lineTo(0,0);
  219. clpMask.endFill();
  220. this.setMask(clpMask);
  221. var enabled = false;
  222. this.onUnload = function()
  223. {
  224.    clearUp();
  225. };
  226.